home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / decomp / pull_const.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-01-23  |  1.6 KB  |  69 lines

  1. # include    <ingres.h>
  2. # include    <symbol.h>
  3. # include    <aux.h>
  4. # include    <tree.h>
  5. # include    "globs.h"
  6. # include    <sccs.h>
  7.  
  8. SCCSID(@(#)pull_const.c    8.1    12/31/84)
  9.  
  10. /*
  11. ** PULL_CONST - Detach and execute all constant clauses in the qualification.
  12. **
  13. **    Pull_const examines the root tree for any constant clauses.
  14. **    If none are present then it returns TRUE. If there are any
  15. **    constant clauses, then they are removed, executed and if
  16. **    TRUE then pull_const returns TRUE and other wise it returns
  17. **    FALSE.
  18. **
  19. **    This routine is not necessary to decomposition but rather
  20. **    can be called as an optimization when constant clauses are
  21. **    expected. Note that without this routine, constant clauses
  22. **    would only be examined at the bottom level of decomposition.
  23. **    Thus a multivar query which was true except for a constant clause
  24. **    would look at the required cross-product space before returning.
  25. */
  26.  
  27. pull_const(root, buf)
  28. QTREE    *root;
  29. char            *buf;
  30. {
  31.     register QTREE    *r, *q, *s;
  32.     QTREE        *makroot();
  33.  
  34.     s = (QTREE *) NULL;
  35.  
  36.     for (r = root; r->right->sym.type != QLEND; )
  37.     {
  38.         q = r;
  39.         r = r->right;    /* r is now the AND node */
  40.  
  41.         if (r->sym.value.sym_root.lvarc == 0)
  42.         {
  43.             /* we have a constant clause */
  44.             if (s == 0)
  45.                 s = makroot(buf);
  46.  
  47.             /* remove AND from root tree */
  48.             q->right = r->right;
  49.  
  50.             /* put node into constant tree */
  51.             r->right = s->right;
  52.             s->right = r;
  53.  
  54.             /* fix up var counts (just for good form!) */
  55.             r->sym.value.sym_root.rvarm = r->sym.value.sym_root.tvarc = 0;
  56.  
  57.             r = q;
  58.         }
  59.     }
  60.  
  61.     if (s)
  62.     {
  63.         /* run the constant query */
  64.         return (execsq1(s, -1, NORESULT));
  65.     }
  66.  
  67.     return (TRUE);
  68. }
  69.